package com.example.tests;


import com.example.page.InternalPage;
import com.example.page.LoginPage;
import com.example.page.MyPageFactory;
import org.junit.After;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.WebDriverWait;
import ru.esteru.selenium.factory.WebDriverFactory;

import java.util.concurrent.TimeUnit;

public class TestBase {
    protected WebDriver driverFirefox;
    private WebDriverWait wait;
    private String baseUrl;

    @Before
	public void setUp() throws Exception {
        driverFirefox = WebDriverFactory.getDriver(DesiredCapabilities.firefox());
        driverFirefox.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        wait = new WebDriverWait(driverFirefox, 40);
		baseUrl = "http://localhost/";
	}

     public LoginPage goToMainPage() {
        driverFirefox.get(baseUrl + "/php4dvd/");
        return MyPageFactory.getPage(driverFirefox, LoginPage.class);
        //loginPage = PageFactory.initElements(driverFirefox, LoginPage.class);
        //somePage =  PageFactory.initElements(driverFirefox, InternalPage.class);
    }

    @After
    public void logout(){
        InternalPage int_page = MyPageFactory.getPage(driverFirefox,InternalPage.class);
        int_page.logOut();
    }
    //public void quit(){
    //    driverFirefox.quit();
    //}
	//public boolean isElementPresent(By by) {
	//	try {
	//		driverFirefox.findElement(by);
	//		return true;
	//	} catch (NoSuchElementException e) {
	//		return false;
	//	}
	//}
}
